using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class RedEditorWindow : EditorWindow
{
    private static bool isFirst;
    [MenuItem("Tools/红点调试")]
    public static void ShowMyWindow()
    {
        RedEditorWindow window = EditorWindow.GetWindow<RedEditorWindow>("红点调试");
 
        window.Show();
        window.minSize = new Vector2(500, 300);
        isFirst = true;
    }

    private Vector2 pos;
    public void OnGUI()
    {
        if (isFirst)
        {
            isFirst = false;
            if (!Application.isPlaying)
            {
                ShowNotification(new GUIContent("请运行时打开"));
                return;
            }
        }
        if (RedPointMgr.Instance.root == null) return;
        pos =  EditorGUILayout.BeginScrollView(pos);
        RecursivePrint(RedPointMgr.Instance.root);
        EditorGUILayout.EndScrollView();
    }

    private static string spr = "---";
    
    public static void RecursivePrint(RedPointNode node)
    {
        if (node.childs.Count < 0)
        {
            return;
        }
        
        string str = "";
        if (node.childs.Count > 0)
        {
            if (node.isExtend)
            {
                str = "V";
            }
            else
            {
                str = ">";
            }
        }
       
        var cur = node;
        while (cur!=null)
        {
            cur = cur.parent;
            str += spr;
        }

        GUIStyle style = new GUIStyle("button");
        style.alignment = TextAnchor.MiddleLeft;

        if (GUILayout.Button($"{str} {node.name}  count:{node.RedCount}",style))
        {
            node.isExtend = !node.isExtend;
        }
        //Debug.Log(str + node.name);
        if (node.isExtend)
        {
            foreach (var redPointNode in node.childs)
            {
                RecursivePrint(redPointNode.Value);
            }
        }
    }
/*
    #region 窗体事件调用
    private void OnProjectChange()
    {
        Debug.Log("当场景改变时调用");
    }
 
    private void OnHierarchyChange()
    {
        Debug.Log("当选择对象属性改变时调用");
    }
 
    void OnGetFocus()
    {
        Debug.Log("当窗口得到焦点时调用");
    }
 
    private void OnLostFocus()
    {
        Debug.Log("当窗口失去焦点时调用");
    }
 
    private void OnSelectionChange()
    {
        Debug.Log("当改变选择不同对象时调用");
    }
 
    private void OnInspectorUpdate()
    {
        Debug.Log("监视面板调用");
    }
 
    private void OnDestroy()
    {
        Debug.Log("当窗口关闭时调用");
    }
 
    private void OnFocus()
    {
        Debug.Log("当窗口获取键盘焦点时调用");
    }
    #endregion
    */
}
